from fastapi import APIRouter, Depends, HTTPException
from crud.user import get_user_page
from schemas.user import User
from schemas.page import Page
from schemas.user import UserSearch
from db.session import SessionLocal
from sqlalchemy.orm import Session

router = APIRouter(tages=["用户中心"], prefix="/admin/user")

# Dependency
def get_db():
    db = SessionLocal()
    try:
        yield db
    finally:
        db.close()

@router.get("/page", summary="分页获取用户")
def user_page(user: User, page: Page,db: Session = Depends(get_db)):
    userSearch = UserSearch()
    userSearch.nickName = user.nickName
    userSearch.status = user.status
    userSearch.page = page
    return get_user_page(db,userSearch)

@router.get("/info/{userId}", summary="用户详情")
def user_info(userId: int):
    return ""


@router.put("/update/{userId}", summary="保存用户")
def update_user(userId: int):
    return ""


@router.delete("/del/{userId}", summary="删除用户")
def del_user(userId: int):
    return ""
